#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
typedef long long LL;
map<char, LL> m;
map<char, LL> s;
struct {
    LL cnt;
    LL list[20];
} se[5];
LL sta[54], sta_cnt=0;
LL num[] = {1,2,3,4};
bool vis[]={0,0,0,0};
LL path[5], p_cnt=0;
void DFS(LL i) {
    bool flag=true;
    for (LL j=0; j<4; ++j) {
        if (!vis[j]) {
            flag=false;
            vis[j]=true;
            path[p_cnt++]=num[j];
            DFS(j);
        }
    }
    vis[i]=false;
    p_cnt--;
    if (flag) {
        LL zz=0;
        for (LL i=0; i<4; ++i){
            zz=zz*10+path[i];
        }
        sta[sta_cnt++] = zz;
    }
}
void Init() {
    m['2']=1;
    m['3']=2;
    m['4']=3;
    m['5']=4;
    m['6']=5;
    m['7']=6;
    m['8']=7;
    m['9']=8;
    m['T']=9;
    m['J']=10;
    m['Q']=11;
    m['K']=12;
    m['A']=13;
    s['s']=1;
    s['h']=2;
    s['d']=3;
    s['c']=4;
    DFS(0);
    p_cnt=24;
}
LL sce[100], s_cnt=1;
LL late[100], l_cnt=1;
LL dp[100];
LL LCS() {
    memset(dp, 0, sizeof(dp));
    for (LL i=1; i<=l_cnt; ++i) {
        for (LL j=1; j<=s_cnt; ++j) {
            if (sce[j]==late[i]) dp[j]=dp[j-1]+1;
            dp[j] = max(dp[j], dp[j-1]);
        }
    }
    return dp[s_cnt-1];
}
char ss[5];
LL haha() {
    return s[ss[1]]*100 + m[ss[0]];
}
bool cmp(LL a, LL b) {
    return a > b;
}
int main(int argc, char** argv) {
    #ifdef hai
    freopen("in.txt", "r", stdin);
    #endif
    Init();
    LL n;
    while (cin>>n) {
        for (LL i=0; i<5; ++i) se[i].cnt=0;
        s_cnt=1;
        for (LL i=0; i<n; ++i) {
            scanf("%s", ss);
            LL t=haha();
            LL mark=t/100;
            se[mark].list[se[mark].cnt++] = t;
            sce[s_cnt++]=t;
        }
        //for (int i=0; i<s_cnt; ++i) cout<<sce[i]<<" ";
        //cout<<endl;
        LL res=0;
        for (LL i=0; i<p_cnt; ++i) {
            for (LL j=0; j<16; ++j) {
                l_cnt=1;
                LL t=sta[i];
                for (LL k=0; k<4; ++k) {
                    LL pos=t%10;
                    t/=10;
                    if(j&(1<<k)) {
                        sort(se[pos].list, se[pos].list+se[pos].cnt, cmp);
                    }
                    else {
                        sort(se[pos].list, se[pos].list+se[pos].cnt);
                    }
                    LL len=se[pos].cnt;
                    for (LL i=0; i<len; ++i) {
                        late[l_cnt++] = se[pos].list[i];
                    }
                }
              //  for (int i=0; i<l_cnt; ++i) cout<<late[i]<<" ";
              //  cout<<endl;
                res = max(res, LCS());
            }
        }
        cout<<n-res<<endl;
    }
    return 0;
}
